//
//  AccountDetailsViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/5/5.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define self_Width CGRectGetWidth([UIScreen mainScreen].bounds)
#define self_Height CGRectGetHeight([UIScreen mainScreen].bounds)

#import "AccountDetailsViewController.h"
#import "LFLUISegmentedControl.h"
#import "AccountDetails1TableViewController.h"
#import "AccountDetails2TableViewController.h"
#import "AccountDetails3TableViewController.h"
#import "AccountDetails4TableViewController.h"
#import "AccountDetails5TableViewController.h"
@interface AccountDetailsViewController ()<LFLUISegmentedControlDelegate,UIScrollViewDelegate>

@property(nonatomic, strong)UIScrollView *mainScrollView; /**< 正文mainSV */
@property (nonatomic ,strong)LFLUISegmentedControl * LFLuisement; /**< LFLuisement */

@end

@implementation AccountDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor redColor];
    self.tabBarController.tabBar.hidden = YES;
    self.title = @"账户明细";
    
    //    1.初次创建：
    LFLUISegmentedControl* LFLuisement=[[LFLUISegmentedControl alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds))];
    LFLuisement.delegate = self;
    //   2.设置显示切换标题数组
    NSArray* LFLarray=[NSArray arrayWithObjects:@"账户",@"购彩",@"派奖",@"充值",@"提现",nil];
    
    [LFLuisement AddSegumentArray:LFLarray];
    //   default Select the Button
    [LFLuisement selectTheSegument:0];
    self.LFLuisement = LFLuisement;
    [self.view addSubview:LFLuisement];
    
    [self createMainScrollView];

}

//创建正文ScrollView内容
- (void)createMainScrollView {
    CGFloat begainScrollViewY = 37+ 0;
    self.mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, begainScrollViewY, self_Width,(self_Height -begainScrollViewY))];
    self.mainScrollView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.mainScrollView];
    self.mainScrollView.bounces = NO;
    self.mainScrollView.pagingEnabled = YES;
    self.mainScrollView.contentSize = CGSizeMake(self_Width * 5, 0);
    //设置代理
    self.mainScrollView.delegate = self;
    
    //添加滚动显示的三个对应的界面view
    for (int i = 0; i < 5; i++) {
        if (i == 0) {
            
            AccountDetails1TableViewController *accountDetails1TableView = [[AccountDetails1TableViewController alloc]init];
            accountDetails1TableView.view.frame = CGRectMake(0,0,self_Width,self_Height-begainScrollViewY);
            
            [self addChildViewController:accountDetails1TableView];
            [self.mainScrollView addSubview:accountDetails1TableView.view];
            
        }else if (i == 1){
            
            AccountDetails2TableViewController *accountDetails2TableView = [[AccountDetails2TableViewController alloc]init];
            accountDetails2TableView.view.frame = CGRectMake(self_Width,0,self_Width,self_Height-begainScrollViewY);
            
            [self addChildViewController:accountDetails2TableView];
            [self.mainScrollView addSubview:accountDetails2TableView.view];
            
        }else if (i == 2){
            
            AccountDetails3TableViewController *accountDetails3TableView = [[AccountDetails3TableViewController alloc]init];
            accountDetails3TableView.view.frame = CGRectMake(self_Width*2,0,self_Width,self_Height-begainScrollViewY);
            
            [self addChildViewController:accountDetails3TableView];
            [self.mainScrollView addSubview:accountDetails3TableView.view];
            
        }else if (i == 3){
            
            AccountDetails4TableViewController *accountDetails4TableView = [[AccountDetails4TableViewController alloc]init];
            accountDetails4TableView.view.frame = CGRectMake(self_Width*3,0,self_Width,self_Height-begainScrollViewY);
            
            [self addChildViewController:accountDetails4TableView];
            [self.mainScrollView addSubview:accountDetails4TableView.view];
            
        }else {
            
            AccountDetails5TableViewController *accountDetails5TableView = [[AccountDetails5TableViewController alloc]init];
            accountDetails5TableView.view.frame = CGRectMake(self_Width*4,0,self_Width,self_Height-begainScrollViewY);
            
            [self addChildViewController:accountDetails5TableView];
            [self.mainScrollView addSubview:accountDetails5TableView.view];
            
        }
    }
}

#pragma mark --- UIScrollView代理方法

static NSInteger pageNumber = 0;

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    pageNumber = (int)(scrollView.contentOffset.x / self_Width + 0.5);
    //    滑动SV里视图,切换标题
    [self.LFLuisement selectTheSegument:pageNumber];
}

#pragma mark ---LFLUISegmentedControlDelegate
/**
 *  点击标题按钮
 *
 *  @param selection 对应下标 begain 0
 */
-(void)uisegumentSelectionChange:(NSInteger)selection{
    //    加入动画,显得不太过于生硬切换
    [UIView animateWithDuration:.2 animations:^{
        [self.mainScrollView setContentOffset:CGPointMake(self_Width *selection, 0)];
    }];
}


@end
